
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyelink_data_count = binder_py('mx_eyelink_data_count')
eyelink_data_count.mx_c.headers = ['<eyelink.h>','"mex.h"','"utils.h"']
eyelink_data_count.bindo += ['utils.o']
eyelink_data_count.mx_c.code = \
"""
INT16 _main( INT16 samples, INT16 events )
{
    return eyelink_data_count( samples, events );
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    
    int s,e;    
    
    /* Verify input arguments. */
    if(nrhs != 2 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    if ( isscalar( prhs[0] ) ){
        INT16 scalar;
        /* Returns the scalar, casts to int if necessary. Returns 0 if */
        /* input is complex. */
        if ( returnscalar( prhs[0], &s ) != 1 )
            mexErrMsgTxt("Complex data is not supported.");                
    } else {
        mexErrMsgTxt("samples should be a scalar."); 
    } 
    
    if ( isscalar( prhs[1] ) ){
        INT16 scalar;
        /* Returns the scalar, casts to int if necessary. Returns 0 if */
        /* input is complex. */
        if ( returnscalar( prhs[1], &e ) != 1 )
            mexErrMsgTxt("Complex data is not supported.");                
    } else {
        mexErrMsgTxt("events should be a scalar."); 
    } 

        
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);    
    *status = (double ) _main( s, e );  
    return;
}
"""

eyelink_data_count.mx_c.mdoc = \
"""function [ ] = mx_eyelink_data_count( )
%MX_EYELINK_DATA_COUNT Counts total items in queue: samples, events, or both.
%
% Parameters:
% samples 	If non-zero count the samples.
% events 	If non-zero count the events.
% Returns:
% Total number of samples and events is in the queue.
%
"""
eyelink_data_count.write_c()
eyelink_data_count.write_m()
eyelink_data_count.compile()
eyelink_data_count.write_sh()

